import {defineStore} from "pinia";

export const useUserStore = defineStore('user', {
    persist: true,
    state: () => {
        return {
            userInfo: {
                id: '',
                avatar: '',
                username: '',
                role: '',
            },
            token: '',
            refreshToken: '',
        }
    },
    /**
     * 封装计算属性，有缓存功能
     */
    getters: {},
    /**
     * 封装业务逻辑，修改state
     */
    actions: {
        logout() {
            this.userInfo = {
                id: '',
                avatar: '',
                username: '',
                role: ''
            }
            this.token = ''
            this.refreshToken = ''
        },
        setUserInfo(val: any) {
            this.userInfo = val
        },
        setToken(val: any) {
            this.token = val
        },
        setRefreshToken(val: any) {
            this.refreshToken = val
        }

    },
})
